Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

338
Visualizações
NextJS call gtag("event") from api route

I'd like to log an event on Google Analytics when an api route is opened.

My gtag implementation is as follows at the moment:

export const logEvent = ({ action, category, label, value }: LogEventProps) => {
  (window as any).gtag("event", action, {
    event_category: category,
    event_label: label,
    value: value,
  });
};

Problem is that it relies on a window for logs to be fired, which is undefined, understandably so, whenever I'm calling this method from an api route.

I couldn't find any valuable information on how to log an event from the server side.

A work-around might be to have the api redirect to a blank page that logs the event, but I don't love the idea and wonder if there's a better approach.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda